<template>
  <div class="content">
    <div class="bf">
      <router-link to="/cart" class="shang">&lt;返回</router-link>
      <p>不凡</p>
    </div>
    <div class="address" @click="come">
      <van-address-list
        v-model="chosenAddressId"
        :list="list"
        default-tag-text="默认"
      />
    </div>

    <div class="tran">
      <span class="one">商品合计</span>
      <span class="two"> ¥{{ total }}</span>
      <div class="gray"></div>
      <span class="three">运费</span>
      <span class="four">免运费</span>
      <div class="gray1"></div>
      <span class="five">优惠券</span>
      <span class="six">暂无</span>
    </div>
    <div>
      <ul class="thing">
        <li v-for="item in goodsList" :key="item.id">
          <img :src="item.list_pic_url" alt="" />
          <input type="checkbox" v-model="item.isChecked" />
          <p class="p1">{{ item.goods_name }}</p>
          <p class="p2">¥{{ item.retail_price }}</p>
          <p class="p3">x{{ item.number }}</p>
        </li>
      </ul>
    </div>

    <div class="last">
      <span class="money">实付:</span>
      <span class="zong"> ¥{{ total }}</span>
      <div class="money"></div>
      <div class="al">
        <p>支付</p>
      </div>
    </div>
  </div>
</template>

<script>
import { list, no } from "@/api/cart/index.js";
export default {
  data() {
    return {
      goodsList: [],
      add: [],
      isAllChecked: false,
      chosenAddressId: "1",
      list: [
        {
          id: "1",
          name: "张三",
          tel: "13000000000",
          address: "浙江省杭州市西湖区文三路 138 号东方通信大厦 7 楼 501 室",
          isDefault: true
        }
      ]
    };
  },

  computed: {
    total() {
      var num = 0;
      for (var i = 0; i < this.goodsList.length; i++) {
        if (this.goodsList[i].isChecked) {
          num += this.goodsList[i].number * this.goodsList[i].retail_price;
        }
      }
      return num;
    }
  },
  created() {
    list({
      openId: "1231"
    }).then(res => {
      console.log(res);
      for (var i = 0; i < res.data.length; i++) {
        res.data[i].isChecked = false;
      }

      this.goodsList = res.data;
    });

    no({
      openId: "1231",
      addressId: "1"
    }).then(res => {
      this.add = res.address;
      console.log(res);
    });
  },
  mounted() {},
  methods: {
    come() {
      this.$router.push({
        name: "cart2"
      });
    }
  }
};
</script>

<style scoped lang="scss">
.al {
  width: 70px;
  height: 50px;
  color: #fff;
  background-color: brown;
  position: absolute;
  left: 270px;
  top: 702px;
}
.al p {
  margin-top: 15px;
}
.zong {
  color: #333;
  position: absolute;
  left: 70px;
  top: 702px;
}
.money {
  color: #333;
  position: absolute;
  left: 30px;
  top: 700px;
}
.content {
  width: 100%;
  height: 1000px;
  background-color: #f5f5f5;
  overflow: hidden;
}
.bf p {
  font-size: 14px;
  color: brown;
}
a {
  text-decoration: none;
  color: brown;
  font-size: 14px;
  position: absolute;
  left: 20px;
  top: 20px;
}
.span {
  margin-left: 20px;
}
.shang {
  display: flex;
  flex-direction: column;
  position: absolute;
  top: 15px;
  left: 30px;
}
.address {
  width: 100%;
  height: 120px;
  //   background-color: #fff;
}
.tran {
  width: 100%;
  height: 150px;
  margin-top: 20px;
  background-color: #fff;
}
.one {
  position: absolute;
  top: 200px;
  left: 20px;
}
.two {
  position: absolute;
  top: 200px;
  left: 290px;
}
.three {
  position: absolute;
  top: 250px;
  left: 20px;
}
.four {
  position: absolute;
  top: 250px;
  left: 290px;
}
.five {
  position: absolute;
  top: 300px;
  left: 20px;
}
.six {
  position: absolute;
  top: 300px;
  left: 290px;
}
.gray {
  width: 320px;
  height: 1.5px;
  background-color: #f5f5f5;
  position: absolute;
  top: 230px;
  left: 20px;
}
.gray1 {
  width: 320px;
  height: 1.5px;
  background-color: #f5f5f5;
  position: absolute;
  top: 290px;
  left: 20px;
}
.thing li {
  width: 100%;
  height: 102px;
  background-color: #fff;
  margin-top: 1px;
}
.thing img {
  width: 70px;
  height: 70px;
  background-color: #f5f5f5;
  position: absolute;
  left: 50px;
  margin-top: 30px;
}
.p1 {
  color: black;
  position: absolute;
  left: 140px;
  margin-top: 40px;
}
.p2 {
  position: absolute;
  left: 140px;
  margin-top: 80px;
}
.p3 {
  position: absolute;
  left: 290px;
  margin-top: 70px;
}
.thing input {
  position: absolute;
  left: 20px;
  margin-top: 55px;
}
</style>
